/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package facade;

/**
 *
 * @author Diegoarpar
 */


import dao.DocumentTypeDAO;
import dao.FranchiseDAO;
import dao.TraceDAO;
import entities.DocumentType;
import entities.Franchise;
import entities.Trace;
import java.util.ArrayList;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;


public class facadeClass {
    static private EntityManagerFactory emf = Persistence.createEntityManagerFactory("SatacreditoDB");
    static private EntityManager em;
    
    public facadeClass() {
      try{
        em= emf.createEntityManager();    
      }catch(Throwable i){
        throw new RuntimeException (i);
      }
    }
     
    public static EntityManager getEntityManager(){
        if(!em.isOpen()){
            em=emf.createEntityManager();
            return em;
            }else
        return em;
        }

    public void crear(Trace object)  {
      TraceDAO traceDao= new TraceDAO();

        try{
        getEntityManager().getTransaction().begin();
          /*
           * PERSIST TRAZA
           */
            traceDao.create(object);
        getEntityManager().getTransaction().commit();
         }   
        catch(Exception i){    
        }
        finally{
              getEntityManager().close();
          }         
    }
    public void crear(Franchise object)  {
      FranchiseDAO traceDao= new FranchiseDAO();
        try{
        getEntityManager().getTransaction().begin();
          /*
           * PERSIST FRANCHISE
           */
            traceDao.create(object);
        getEntityManager().getTransaction().commit();
         }   
        catch(Exception i){        
        }
        finally{
              getEntityManager().close();
          }         
    }
    public void crear(DocumentType object)  {
      DocumentTypeDAO traceDao= new DocumentTypeDAO();
        try{
        getEntityManager().getTransaction().begin();
          /*
           * PERSIST FRANCHISE
           */
            traceDao.create(object);
        getEntityManager().getTransaction().commit();
         }   
        catch(Exception i){        
        }
        finally{
              getEntityManager().close();
          }         
    }
}